<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Box2D APi: C:/Users/ARme/Desktop/box2d/Box2D/Collision/b2BroadPhase.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Box2D APi
   &#160;<span id="projectnumber">251</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('b2_broad_phase_8h.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">C:/Users/ARme/Desktop/box2d/Box2D/Collision/b2BroadPhase.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org</span>
<a name="l00003"></a>00003 <span class="comment">*</span>
<a name="l00004"></a>00004 <span class="comment">* This software is provided &#39;as-is&#39;, without any express or implied</span>
<a name="l00005"></a>00005 <span class="comment">* warranty.  In no event will the authors be held liable for any damages</span>
<a name="l00006"></a>00006 <span class="comment">* arising from the use of this software.</span>
<a name="l00007"></a>00007 <span class="comment">* Permission is granted to anyone to use this software for any purpose,</span>
<a name="l00008"></a>00008 <span class="comment">* including commercial applications, and to alter it and redistribute it</span>
<a name="l00009"></a>00009 <span class="comment">* freely, subject to the following restrictions:</span>
<a name="l00010"></a>00010 <span class="comment">* 1. The origin of this software must not be misrepresented; you must not</span>
<a name="l00011"></a>00011 <span class="comment">* claim that you wrote the original software. If you use this software</span>
<a name="l00012"></a>00012 <span class="comment">* in a product, an acknowledgment in the product documentation would be</span>
<a name="l00013"></a>00013 <span class="comment">* appreciated but is not required.</span>
<a name="l00014"></a>00014 <span class="comment">* 2. Altered source versions must be plainly marked as such, and must not be</span>
<a name="l00015"></a>00015 <span class="comment">* misrepresented as being the original software.</span>
<a name="l00016"></a>00016 <span class="comment">* 3. This notice may not be removed or altered from any source distribution.</span>
<a name="l00017"></a>00017 <span class="comment">*/</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#ifndef B2_BROAD_PHASE_H</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define B2_BROAD_PHASE_H</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;<a class="code" href="b2_settings_8h.html">Box2D/Common/b2Settings.h</a>&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;<a class="code" href="b2_collision_8h.html">Box2D/Collision/b2Collision.h</a>&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;Box2D/Collision/b2DynamicTree.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a><a class="code" href="structb2_pair.html">00027</a> <span class="keyword">struct </span><a class="code" href="structb2_pair.html">b2Pair</a>
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029         int32 proxyIdA;
<a name="l00030"></a>00030         int32 proxyIdB;
<a name="l00031"></a>00031 };
<a name="l00032"></a>00032 
<a name="l00036"></a><a class="code" href="classb2_broad_phase.html">00036</a> <span class="keyword">class </span><a class="code" href="classb2_broad_phase.html">b2BroadPhase</a>
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038 <span class="keyword">public</span>:
<a name="l00039"></a>00039 
<a name="l00040"></a>00040         <span class="keyword">enum</span>
<a name="l00041"></a>00041         {
<a name="l00042"></a>00042                 e_nullProxy = -1
<a name="l00043"></a>00043         };
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         <a class="code" href="classb2_broad_phase.html">b2BroadPhase</a>();
<a name="l00046"></a>00046         ~<a class="code" href="classb2_broad_phase.html">b2BroadPhase</a>();
<a name="l00047"></a>00047 
<a name="l00050"></a>00050         int32 <a class="code" href="classb2_broad_phase.html#ae2f7af756bc55ece45221466c5af449c">CreateProxy</a>(<span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb, <span class="keywordtype">void</span>* userData);
<a name="l00051"></a>00051 
<a name="l00053"></a>00053         <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#a84f0fb227dc01a9b9baa55c7b8c68984" title="Destroy a proxy. It is up to the client to remove any pairs.">DestroyProxy</a>(int32 proxyId);
<a name="l00054"></a>00054 
<a name="l00057"></a>00057         <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#a01dc18a19c2b5d0cc1d9cd8c8554234c">MoveProxy</a>(int32 proxyId, <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb, <span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; displacement);
<a name="l00058"></a>00058 
<a name="l00060"></a>00060         <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#a67b296431ebbc7b44037f21d645d9166" title="Call to trigger a re-processing of it&#39;s pairs on the next call to UpdatePairs.">TouchProxy</a>(int32 proxyId);
<a name="l00061"></a>00061 
<a name="l00063"></a>00063         <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; <a class="code" href="classb2_broad_phase.html#a7b00ac700db52e52248a25397007d4ff" title="Get the fat AABB for a proxy.">GetFatAABB</a>(int32 proxyId) <span class="keyword">const</span>;
<a name="l00064"></a>00064 
<a name="l00066"></a>00066         <span class="keywordtype">void</span>* <a class="code" href="classb2_broad_phase.html#a89c099e95237d68577376d8f9a4ed013" title="Get user data from a proxy. Returns NULL if the id is invalid.">GetUserData</a>(int32 proxyId) <span class="keyword">const</span>;
<a name="l00067"></a>00067 
<a name="l00069"></a>00069         <span class="keywordtype">bool</span> <a class="code" href="classb2_broad_phase.html#a1785eb29d14997d81bd537f064d22aba" title="Test overlap of fat AABBs.">TestOverlap</a>(int32 proxyIdA, int32 proxyIdB) <span class="keyword">const</span>;
<a name="l00070"></a>00070 
<a name="l00072"></a>00072         int32 <a class="code" href="classb2_broad_phase.html#a399fa4f5289a1ec46a65f726f3bac890" title="Get the number of proxies.">GetProxyCount</a>() <span class="keyword">const</span>;
<a name="l00073"></a>00073 
<a name="l00075"></a>00075         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00076"></a>00076         <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#a0a1acd693466b997700242ae00784c20" title="Update the pairs. This results in pair callbacks. This can only add pairs.">UpdatePairs</a>(T* callback);
<a name="l00077"></a>00077 
<a name="l00080"></a>00080         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00081"></a>00081         <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#aea5732362c8bb3959c6b24f967654d93">Query</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb) <span class="keyword">const</span>;
<a name="l00082"></a>00082 
<a name="l00090"></a>00090         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00091"></a>00091         <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#aebcb837120ce45bbb82b4b61db533026">RayCast</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_ray_cast_input.html" title="Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).">b2RayCastInput</a>&amp; input) <span class="keyword">const</span>;
<a name="l00092"></a>00092 
<a name="l00094"></a>00094         int32 <a class="code" href="classb2_broad_phase.html#aeb9f94f44840c5bd766031d78f63ca08" title="Get the height of the embedded tree.">GetTreeHeight</a>() <span class="keyword">const</span>;
<a name="l00095"></a>00095 
<a name="l00097"></a>00097         int32 <a class="code" href="classb2_broad_phase.html#a1189e783d39bfd69b314284ce52ea3c3" title="Get the balance of the embedded tree.">GetTreeBalance</a>() <span class="keyword">const</span>;
<a name="l00098"></a>00098 
<a name="l00100"></a>00100         float32 <a class="code" href="classb2_broad_phase.html#abe02c30ca1b3b9c9b84a571a2f8cef92" title="Get the quality metric of the embedded tree.">GetTreeQuality</a>() <span class="keyword">const</span>;
<a name="l00101"></a>00101 
<a name="l00105"></a>00105         <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#a410e6115e3d1b4fca61cfbf397767772">ShiftOrigin</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; newOrigin);
<a name="l00106"></a>00106 
<a name="l00107"></a>00107 <span class="keyword">private</span>:
<a name="l00108"></a>00108 
<a name="l00109"></a>00109         <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classb2_dynamic_tree.html">b2DynamicTree</a>;
<a name="l00110"></a>00110 
<a name="l00111"></a>00111         <span class="keywordtype">void</span> BufferMove(int32 proxyId);
<a name="l00112"></a>00112         <span class="keywordtype">void</span> UnBufferMove(int32 proxyId);
<a name="l00113"></a>00113 
<a name="l00114"></a>00114         <span class="keywordtype">bool</span> QueryCallback(int32 proxyId);
<a name="l00115"></a>00115 
<a name="l00116"></a>00116         <a class="code" href="classb2_dynamic_tree.html">b2DynamicTree</a> m_tree;
<a name="l00117"></a>00117 
<a name="l00118"></a>00118         int32 m_proxyCount;
<a name="l00119"></a>00119 
<a name="l00120"></a>00120         int32* m_moveBuffer;
<a name="l00121"></a>00121         int32 m_moveCapacity;
<a name="l00122"></a>00122         int32 m_moveCount;
<a name="l00123"></a>00123 
<a name="l00124"></a>00124         <a class="code" href="structb2_pair.html">b2Pair</a>* m_pairBuffer;
<a name="l00125"></a>00125         int32 m_pairCapacity;
<a name="l00126"></a>00126         int32 m_pairCount;
<a name="l00127"></a>00127 
<a name="l00128"></a>00128         int32 m_queryProxyId;
<a name="l00129"></a>00129 };
<a name="l00130"></a>00130 
<a name="l00132"></a>00132 <span class="keyword">inline</span> <span class="keywordtype">bool</span> b2PairLessThan(<span class="keyword">const</span> <a class="code" href="structb2_pair.html">b2Pair</a>&amp; pair1, <span class="keyword">const</span> <a class="code" href="structb2_pair.html">b2Pair</a>&amp; pair2)
<a name="l00133"></a>00133 {
<a name="l00134"></a>00134         <span class="keywordflow">if</span> (pair1.proxyIdA &lt; pair2.proxyIdA)
<a name="l00135"></a>00135         {
<a name="l00136"></a>00136                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00137"></a>00137         }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         <span class="keywordflow">if</span> (pair1.proxyIdA == pair2.proxyIdA)
<a name="l00140"></a>00140         {
<a name="l00141"></a>00141                 <span class="keywordflow">return</span> pair1.proxyIdB &lt; pair2.proxyIdB;
<a name="l00142"></a>00142         }
<a name="l00143"></a>00143 
<a name="l00144"></a>00144         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146 
<a name="l00147"></a><a class="code" href="classb2_broad_phase.html#a89c099e95237d68577376d8f9a4ed013">00147</a> <span class="keyword">inline</span> <span class="keywordtype">void</span>* <a class="code" href="classb2_broad_phase.html#a89c099e95237d68577376d8f9a4ed013" title="Get user data from a proxy. Returns NULL if the id is invalid.">b2BroadPhase::GetUserData</a>(int32 proxyId)<span class="keyword"> const</span>
<a name="l00148"></a>00148 <span class="keyword"></span>{
<a name="l00149"></a>00149         <span class="keywordflow">return</span> m_tree.<a class="code" href="classb2_dynamic_tree.html#a44ab57dce3c42b0a5847a64e489a71ce">GetUserData</a>(proxyId);
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 
<a name="l00152"></a><a class="code" href="classb2_broad_phase.html#a1785eb29d14997d81bd537f064d22aba">00152</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classb2_broad_phase.html#a1785eb29d14997d81bd537f064d22aba" title="Test overlap of fat AABBs.">b2BroadPhase::TestOverlap</a>(int32 proxyIdA, int32 proxyIdB)<span class="keyword"> const</span>
<a name="l00153"></a>00153 <span class="keyword"></span>{
<a name="l00154"></a>00154         <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabbA = m_tree.<a class="code" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687" title="Get the fat AABB for a proxy.">GetFatAABB</a>(proxyIdA);
<a name="l00155"></a>00155         <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabbB = m_tree.<a class="code" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687" title="Get the fat AABB for a proxy.">GetFatAABB</a>(proxyIdB);
<a name="l00156"></a>00156         <span class="keywordflow">return</span> b2TestOverlap(aabbA, aabbB);
<a name="l00157"></a>00157 }
<a name="l00158"></a>00158 
<a name="l00159"></a><a class="code" href="classb2_broad_phase.html#a7b00ac700db52e52248a25397007d4ff">00159</a> <span class="keyword">inline</span> <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; <a class="code" href="classb2_broad_phase.html#a7b00ac700db52e52248a25397007d4ff" title="Get the fat AABB for a proxy.">b2BroadPhase::GetFatAABB</a>(int32 proxyId)<span class="keyword"> const</span>
<a name="l00160"></a>00160 <span class="keyword"></span>{
<a name="l00161"></a>00161         <span class="keywordflow">return</span> m_tree.<a class="code" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687" title="Get the fat AABB for a proxy.">GetFatAABB</a>(proxyId);
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 
<a name="l00164"></a><a class="code" href="classb2_broad_phase.html#a399fa4f5289a1ec46a65f726f3bac890">00164</a> <span class="keyword">inline</span> int32 <a class="code" href="classb2_broad_phase.html#a399fa4f5289a1ec46a65f726f3bac890" title="Get the number of proxies.">b2BroadPhase::GetProxyCount</a>()<span class="keyword"> const</span>
<a name="l00165"></a>00165 <span class="keyword"></span>{
<a name="l00166"></a>00166         <span class="keywordflow">return</span> m_proxyCount;
<a name="l00167"></a>00167 }
<a name="l00168"></a>00168 
<a name="l00169"></a><a class="code" href="classb2_broad_phase.html#aeb9f94f44840c5bd766031d78f63ca08">00169</a> <span class="keyword">inline</span> int32 <a class="code" href="classb2_broad_phase.html#aeb9f94f44840c5bd766031d78f63ca08" title="Get the height of the embedded tree.">b2BroadPhase::GetTreeHeight</a>()<span class="keyword"> const</span>
<a name="l00170"></a>00170 <span class="keyword"></span>{
<a name="l00171"></a>00171         <span class="keywordflow">return</span> m_tree.<a class="code" href="classb2_dynamic_tree.html#add7e09cdf279e7c0031da9dfd4cdf4db">GetHeight</a>();
<a name="l00172"></a>00172 }
<a name="l00173"></a>00173 
<a name="l00174"></a><a class="code" href="classb2_broad_phase.html#a1189e783d39bfd69b314284ce52ea3c3">00174</a> <span class="keyword">inline</span> int32 <a class="code" href="classb2_broad_phase.html#a1189e783d39bfd69b314284ce52ea3c3" title="Get the balance of the embedded tree.">b2BroadPhase::GetTreeBalance</a>()<span class="keyword"> const</span>
<a name="l00175"></a>00175 <span class="keyword"></span>{
<a name="l00176"></a>00176         <span class="keywordflow">return</span> m_tree.<a class="code" href="classb2_dynamic_tree.html#ae02c45d1a68b42e59d170438ddbb7977">GetMaxBalance</a>();
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178 
<a name="l00179"></a><a class="code" href="classb2_broad_phase.html#abe02c30ca1b3b9c9b84a571a2f8cef92">00179</a> <span class="keyword">inline</span> float32 <a class="code" href="classb2_broad_phase.html#abe02c30ca1b3b9c9b84a571a2f8cef92" title="Get the quality metric of the embedded tree.">b2BroadPhase::GetTreeQuality</a>()<span class="keyword"> const</span>
<a name="l00180"></a>00180 <span class="keyword"></span>{
<a name="l00181"></a>00181         <span class="keywordflow">return</span> m_tree.<a class="code" href="classb2_dynamic_tree.html#ad78282a720c451e032b43c34cba02f1a" title="Get the ratio of the sum of the node areas to the root area.">GetAreaRatio</a>();
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 
<a name="l00184"></a>00184 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00185"></a><a class="code" href="classb2_broad_phase.html#a0a1acd693466b997700242ae00784c20">00185</a> <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#a0a1acd693466b997700242ae00784c20" title="Update the pairs. This results in pair callbacks. This can only add pairs.">b2BroadPhase::UpdatePairs</a>(T* callback)
<a name="l00186"></a>00186 {
<a name="l00187"></a>00187         <span class="comment">// Reset pair buffer</span>
<a name="l00188"></a>00188         m_pairCount = 0;
<a name="l00189"></a>00189 
<a name="l00190"></a>00190         <span class="comment">// Perform tree queries for all moving proxies.</span>
<a name="l00191"></a>00191         <span class="keywordflow">for</span> (int32 i = 0; i &lt; m_moveCount; ++i)
<a name="l00192"></a>00192         {
<a name="l00193"></a>00193                 m_queryProxyId = m_moveBuffer[i];
<a name="l00194"></a>00194                 <span class="keywordflow">if</span> (m_queryProxyId == e_nullProxy)
<a name="l00195"></a>00195                 {
<a name="l00196"></a>00196                         <span class="keywordflow">continue</span>;
<a name="l00197"></a>00197                 }
<a name="l00198"></a>00198 
<a name="l00199"></a>00199                 <span class="comment">// We have to query the tree with the fat AABB so that</span>
<a name="l00200"></a>00200                 <span class="comment">// we don&#39;t fail to create a pair that may touch later.</span>
<a name="l00201"></a>00201                 <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; fatAABB = m_tree.<a class="code" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687" title="Get the fat AABB for a proxy.">GetFatAABB</a>(m_queryProxyId);
<a name="l00202"></a>00202 
<a name="l00203"></a>00203                 <span class="comment">// Query tree, create pairs and add them pair buffer.</span>
<a name="l00204"></a>00204                 m_tree.<a class="code" href="classb2_dynamic_tree.html#adf70aee89b4692fc79d65b1f54308585">Query</a>(<span class="keyword">this</span>, fatAABB);
<a name="l00205"></a>00205         }
<a name="l00206"></a>00206 
<a name="l00207"></a>00207         <span class="comment">// Reset move buffer</span>
<a name="l00208"></a>00208         m_moveCount = 0;
<a name="l00209"></a>00209 
<a name="l00210"></a>00210         <span class="comment">// Sort the pair buffer to expose duplicates.</span>
<a name="l00211"></a>00211         std::sort(m_pairBuffer, m_pairBuffer + m_pairCount, b2PairLessThan);
<a name="l00212"></a>00212 
<a name="l00213"></a>00213         <span class="comment">// Send the pairs back to the client.</span>
<a name="l00214"></a>00214         int32 i = 0;
<a name="l00215"></a>00215         <span class="keywordflow">while</span> (i &lt; m_pairCount)
<a name="l00216"></a>00216         {
<a name="l00217"></a>00217                 <a class="code" href="structb2_pair.html">b2Pair</a>* primaryPair = m_pairBuffer + i;
<a name="l00218"></a>00218                 <span class="keywordtype">void</span>* userDataA = m_tree.<a class="code" href="classb2_dynamic_tree.html#a44ab57dce3c42b0a5847a64e489a71ce">GetUserData</a>(primaryPair-&gt;proxyIdA);
<a name="l00219"></a>00219                 <span class="keywordtype">void</span>* userDataB = m_tree.<a class="code" href="classb2_dynamic_tree.html#a44ab57dce3c42b0a5847a64e489a71ce">GetUserData</a>(primaryPair-&gt;proxyIdB);
<a name="l00220"></a>00220 
<a name="l00221"></a>00221                 callback-&gt;AddPair(userDataA, userDataB);
<a name="l00222"></a>00222                 ++i;
<a name="l00223"></a>00223 
<a name="l00224"></a>00224                 <span class="comment">// Skip any duplicate pairs.</span>
<a name="l00225"></a>00225                 <span class="keywordflow">while</span> (i &lt; m_pairCount)
<a name="l00226"></a>00226                 {
<a name="l00227"></a>00227                         <a class="code" href="structb2_pair.html">b2Pair</a>* pair = m_pairBuffer + i;
<a name="l00228"></a>00228                         <span class="keywordflow">if</span> (pair-&gt;proxyIdA != primaryPair-&gt;proxyIdA || pair-&gt;proxyIdB != primaryPair-&gt;proxyIdB)
<a name="l00229"></a>00229                         {
<a name="l00230"></a>00230                                 <span class="keywordflow">break</span>;
<a name="l00231"></a>00231                         }
<a name="l00232"></a>00232                         ++i;
<a name="l00233"></a>00233                 }
<a name="l00234"></a>00234         }
<a name="l00235"></a>00235 
<a name="l00236"></a>00236         <span class="comment">// Try to keep the tree balanced.</span>
<a name="l00237"></a>00237         <span class="comment">//m_tree.Rebalance(4);</span>
<a name="l00238"></a>00238 }
<a name="l00239"></a>00239 
<a name="l00240"></a>00240 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00241"></a><a class="code" href="classb2_broad_phase.html#aea5732362c8bb3959c6b24f967654d93">00241</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#aea5732362c8bb3959c6b24f967654d93">b2BroadPhase::Query</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_a_a_b_b.html" title="An axis aligned bounding box.">b2AABB</a>&amp; aabb)<span class="keyword"> const</span>
<a name="l00242"></a>00242 <span class="keyword"></span>{
<a name="l00243"></a>00243         m_tree.<a class="code" href="classb2_dynamic_tree.html#adf70aee89b4692fc79d65b1f54308585">Query</a>(callback, aabb);
<a name="l00244"></a>00244 }
<a name="l00245"></a>00245 
<a name="l00246"></a>00246 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00247"></a><a class="code" href="classb2_broad_phase.html#aebcb837120ce45bbb82b4b61db533026">00247</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#aebcb837120ce45bbb82b4b61db533026">b2BroadPhase::RayCast</a>(T* callback, <span class="keyword">const</span> <a class="code" href="structb2_ray_cast_input.html" title="Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).">b2RayCastInput</a>&amp; input)<span class="keyword"> const</span>
<a name="l00248"></a>00248 <span class="keyword"></span>{
<a name="l00249"></a>00249         m_tree.<a class="code" href="classb2_dynamic_tree.html#abd7a5c6a5bc109dbbdb0ec3aae039648">RayCast</a>(callback, input);
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251 
<a name="l00252"></a><a class="code" href="classb2_broad_phase.html#a410e6115e3d1b4fca61cfbf397767772">00252</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classb2_broad_phase.html#a410e6115e3d1b4fca61cfbf397767772">b2BroadPhase::ShiftOrigin</a>(<span class="keyword">const</span> <a class="code" href="structb2_vec2.html" title="A 2D column vector.">b2Vec2</a>&amp; newOrigin)
<a name="l00253"></a>00253 {
<a name="l00254"></a>00254         m_tree.<a class="code" href="classb2_dynamic_tree.html#af37ddfed6a5da97d5a78b09918d19ceb">ShiftOrigin</a>(newOrigin);
<a name="l00255"></a>00255 }
<a name="l00256"></a>00256 
<a name="l00257"></a>00257 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>b2BroadPhase.h</b>      </li>

    <li class="footer">Generated on Mon Sep 17 2012 15:56:57 for Box2D APi by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
